package com.bc.bczbweb.controller.Ajax;

import com.bc.bcapi.service.T_Sendcoin_logService;
import com.bc.bcmodel.enums.SendCoinEnum;
import com.bc.commoncore.util.DateUtil;
import com.bc.commonentity.common.JsonResult;
import com.bc.bcapi.service.T_User_elitesService;
import com.bc.bcmodel.domain.T_User_elitesModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.ws.rs.POST;
import java.math.BigInteger;

@RestController
@RequestMapping("ajax/t_user_elites")
public class AjaxT_User_elitesController {
    @Autowired
    T_User_elitesService t_User_elitesService;
    @Autowired
    T_Sendcoin_logService t_sendcoin_logService;

    @POST
    @RequestMapping(value = "add", method = RequestMethod.POST)
    public JsonResult add(T_User_elitesModel req) {
        JsonResult js = new JsonResult();
        if (req.getIs_business_status() != null && req.getIs_business_status() == 1) {
            req.setBusiness_auth_time(DateUtil.getToday());
            t_sendcoin_logService.setSendCoin(SendCoinEnum.ELITESSUCCESS, req.getUser_id(), req.getUser_id());
        }
        if (req.getIs_code_status() != null && req.getIs_code_status() == 1) {
            t_sendcoin_logService.setSendCoin(SendCoinEnum.ELITESSUCCESS, req.getUser_id(), req.getUser_id());
            req.setCode_auth_time(DateUtil.getToday());
        }
        t_User_elitesService.update(req);
        return js;
    }

    @RequestMapping("del")
    public JsonResult del(BigInteger id) {
        JsonResult js = new JsonResult();
        t_User_elitesService.delete(id);
        return js;
    }
}